package com.ylbh.modules.home.controller;

import com.ylbh.common.pojo.home.dto.BusinessIntegralDTO;
import com.ylbh.common.pojo.home.dto.ClassifiedSalesDTO;
import com.ylbh.common.pojo.home.dto.OrderRingDiagramDTO;
import com.ylbh.common.pojo.home.dto.SingleQuantityTrendDTO;
import com.ylbh.common.pojo.home.vo.*;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.app.service.UserService;
import com.ylbh.modules.home.service.HomeService;
import com.ylbh.modules.sys.entity.SysUserEntity;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页
 * @author czx
 */
@RestController
@RequestMapping("/home")
public class HomeController {

    @Autowired
    private UserService userService;

    @Autowired
    private HomeService homeService;

    @RequestMapping("queryWeeklyStatistics")
    @ApiOperation("首页统计")
    public CommonResult<HomeListVO> queryWeeklyStatistics(){
        HomeListVO vo = userService.queryWeeklyStatistics();
        return Ref.ok(vo);
    }

    @ApiOperation("首页-待处理事务")
    @GetMapping("queryToBeProcessed")
    public CommonResult<List<Integer>> queryToBeProcessed() {
        List<Integer> list = homeService.queryToBeProcessed();
        return Ref.ok(list);
    }

    @ApiOperation("首页-数据概览")
    @GetMapping("queryDataOverview")
    public CommonResult<HomeDataOverviewVO> queryDataOverview() {
        HomeDataOverviewVO vo = homeService.queryDataOverview();
        return Ref.ok(vo);
    }

    @ApiOperation("首页-商城商品信息")
    @GetMapping("queryMallInformation")
    public CommonResult<List> queryMallInformation() {
        List<HomeMallInformationVO> list = homeService.queryMallInformation();
        return Ref.ok(list);
    }

    @ApiOperation("首页-订单环形图")
    @GetMapping("queryOrderRingDiagram")
    public CommonResult<?> queryOrderRingDiagram(OrderRingDiagramDTO orderRingDiagramDTO) {
        List<?> vo = homeService.queryOrderRingDiagram(orderRingDiagramDTO);
        return Ref.ok(vo);
    }

    @ApiOperation("首页-单量走势")
    @GetMapping("querySingleQuantityTrend")
    public CommonResult<?> querySingleQuantityTrend(SingleQuantityTrendDTO singleQuantityTrendDTO) {
        HomeTrendVO list = homeService.querySingleQuantityTrend(singleQuantityTrendDTO);
        return Ref.ok(list);
    }

    /**
     * @param timeRange 时间范围
     * @param type (1:商热排行;2:商滞排行;3:商转排行;4:联销排行;5:热搜排行;6:会员消费排行;7:会员联盟消费排行;8:复购统计)
     * @param sortType (true:表示是以成交量倒序; false:表示是以成交金额排序）
     * @return
     */
    @ApiOperation("消费排行")
    @GetMapping("queryConsumptionRanking")
    public CommonResult queryConsumptionRanking(@RequestParam(value = "timeRange") String timeRange, @RequestParam(value = "type") Integer type, @RequestParam(value = "sortType") Boolean sortType) {
        List<HomeConsumptionRankingVO> list = homeService.queryConsumptionRanking(timeRange, type, sortType);
        return Ref.ok(list);
    }

    @ApiOperation("商城各分类商品销量")
    @GetMapping("queryClassifiedSales")
    public CommonResult queryClassifiedSales(ClassifiedSalesDTO classifiedSalesDTO) {
        List<ClassifiedSalesVO> list = homeService.queryClassifiedSales(classifiedSalesDTO);
        return Ref.ok(list);
    }

    @ApiOperation("联盟店积分走势")
    @GetMapping("queryBusinessIntegral")
    public CommonResult queryBusinessIntegral(BusinessIntegralDTO businessIntegralDTO) {
        HomeTrendVO list = homeService.queryBusinessIntegral(businessIntegralDTO);
        return Ref.ok(list);
    }

    @ApiOperation("查询出所有非公司系统用户的信息")
    @GetMapping("queryAllUserId")
    public CommonResult queryAllUserId() {
        List<Integer> list = homeService.queryAllUserId();
        return Ref.ok(list);
    }

}
